function main(str) {
  const res = []
  let strA = str.split('')
  process(strA, 0, res)
  return res
}

function process(strA, i, res) {
  if(i == strA.length) {
    res.push(strA.join(''))
  }
  for(let j = i; j<strA.length; j++) {
    swap(strA, i , j)
    process(strA, i+1, res)
    swap(strA, i ,j)
  }
}

function swap(arr, i , j) {
  let temp = arr[i]
  arr[i] = arr[j]
  arr[j] = temp
}

const a = main('abc')
console.log(a)